﻿/*
 * Copyright © 2020, Wuxi Safover Intelligent Technology Co., Ltd. All rights reserved.
 * 
 * 无锡安永智能科技有限公司版权所有，未经许可，不得用于商业用途
 * 
 * Visit: https://www.safover.com/ 
 */

using Newtonsoft.Json;
using System.IO;
using System.Text;

namespace Safover.LidarCollector.Extensions
{
    public class Json
    {
        public static T DeserializeObject<T>(string StoragePath, JsonSerializerSettings settings = null)
        {
            var strJson = File.ReadAllText(StoragePath, Encoding.ASCII);

            return JsonConvert.DeserializeObject<T>(strJson, settings);
        }

        public static void SerializeObject<T>(T o, string StoragePath, JsonSerializerSettings settings, Formatting formatting = Formatting.Indented)
        {
            var strJson = JsonConvert.SerializeObject(o, typeof(T), formatting, settings);

            File.WriteAllText(StoragePath, strJson);
        }

        public static string SerializeObject<T>(T o, JsonSerializerSettings settings, Formatting formatting = Formatting.Indented)
        {
            return JsonConvert.SerializeObject(o, typeof(T), formatting, settings);
        }

    }
}
